package com.nhim.cms.domain;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Version;

import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.Table;

/**
 * Group entity. @author Huy Lieu Ta
 */
@Entity
@Table(name = "nhim_group", catalog = "nhim_cms")
public class Group implements java.io.Serializable {

	// Fields

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Integer id;
	private String name;
	private String description;
	private Integer version;
	private Set<ContentType> contentTypes = new HashSet<ContentType>(0);

	// Constructors

	/** default constructor */
	public Group() {
	}

	/** minimal constructor */
	public Group(String name) {
		this.name = name;
	}

	/** full constructor */
	public Group(String name, String description, String domain,
			String path, String errorUrl,Integer version) {
		this.name = name;
		this.description = description;
		this.version = version;
	}

	// Property accessors
	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "id", unique = true, nullable = false)
	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@Column(name = "name", nullable = false, length = 100)
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "description", length = 200)
	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}
	
	@ManyToMany(cascade = {CascadeType.PERSIST,CascadeType.MERGE,CascadeType.DETACH,CascadeType.REFRESH}, fetch = FetchType.LAZY)
	@JoinTable(name = "nhim_content_type_group", catalog = "nhim_cms", joinColumns = { @JoinColumn(name = "group_id", nullable = false, updatable = true) }, inverseJoinColumns = { @JoinColumn(name = "content_type_id", nullable = false, updatable = true) })
	public Set<ContentType> getContentTypes() {
		return this.contentTypes;
	}

	public void setContentTypes(Set<ContentType> contentTypes) {
		this.contentTypes = contentTypes;
	}

	@Version
	@Column(name = "version")
	public Integer getVersion() {
		return this.version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

}